//app.js
var config = require("utils/config.js")
const api = require('utils/api.js')

App({
  onLaunch: function () {
    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        // wx.redirectTo({
        //   url: '/pages/sign/sign',
        // })
        // return

        wx.setStorageSync('openid', '')
        var openid = ''
        // get openid
        api.get('getUserId', {
          'code': res.code
        }).then(res2 => {
          openid = res2.openid
          wx.setStorageSync('openid', openid)
        }).catch(e => {
          wx.showToast({
            title: 'get user id fail',
          })
        })
      }
    })

  }
})